package com.caigou.controller;

import com.caigou.bean.cms.param.CollectionParam;
import com.caigou.service.CollectionService;
import com.caigou.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/collection")
public class CollectionController {

    @Resource
    private CollectionService collectionService;

    @ApiOperation("获取采集源配置列表")
    @RequestMapping("/loadCollectionList")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result loadCollectionList(@RequestBody CollectionParam param){
        return collectionService.loadCollectionList(param);
    }

    @ApiOperation("保存采集源时间配置")
    @RequestMapping("/saveCollectionTimeConfig")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result saveCollectionTimeConfig(@RequestBody CollectionParam param){
        return collectionService.saveCollectionTimeConfig(param);
    }

    @ApiOperation("删除采集源时间配置")
    @RequestMapping("/deleteCollectionTimeConfig")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result deleteCollectionTimeConfig(@RequestBody CollectionParam param){
        return collectionService.deleteCollectionTimeConfig(param);
    }

    @ApiOperation("更新采集源状态(异常状态+启用状态)")
    @RequestMapping("/updateCollectionStatus")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result updateCollectionStatus(@RequestBody CollectionParam param){
        return collectionService.updateCollectionStatus(param);
    }

    @ApiOperation("更新采集源异常配置信息")
    @RequestMapping("/updateCollectionErrorConfig")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result updateCollectionErrorConfig(@RequestBody CollectionParam param){
        return collectionService.updateCollectionErrorConfig(param);
    }

    @ApiOperation("获取全部采集源数量信息")
    @RequestMapping("/loadCollectionCountInfo")
    @PreAuthorize("hasAnyAuthority('caijiyuanshezhi')")
    public Result loadCollectionCountInfo(){
        return collectionService.loadCollectionCountInfo();
    }

    @ApiOperation("清空分站数据")
    @RequestMapping("/deleteSubstationData")
    public Result deleteSubstationData(@RequestBody CollectionParam param){
        return collectionService.deleteSubstationData(param);
    }
}
